package com.java.shop.member.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.java.common.utils.PageUtils;
import com.java.common.utils.R;
import com.java.shop.member.feign.OrderFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;

@Controller
public class MemberWebController {
    @Autowired
    OrderFeignService orderFeignService;

    @GetMapping("/memberOrder.html")
    public String memberOrderPage(@RequestParam(value = "pageNum",defaultValue = "1") String pageNum, Model model){
        HashMap<String, Object> map = new HashMap<>();
        map.put("page",pageNum);
        R r = orderFeignService.listWithItem(map);
        if(r.getCode() == 0){
            System.out.println(r);
            PageUtils page = JSON.parseObject(r.getData("page"), new TypeReference<PageUtils>() {});
            model.addAttribute("orderPage",page);
        }
        return "orderList";
    }
}
